<?php

require_once __DIR__ . '/vendor/autoload.php';

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$connection = new AMQPStreamConnection('192.168.10.10',5672,'admin','admin');


$channel = $connection ->channel();
$channel->exchange_declare('log','fanout',false,true,false);

list($queue_name,,) =$channel-> queue_declare("",false,true,false,false);

$channel->queue_bind($queue_name,'log');

echo ' [*] Waiting for logs. To exit press CTRL+C', "\n";


$callback = function($msg){
    echo ' [x] ', $msg->body, "\n";
  };
  
  $channel->basic_consume($queue_name, '', false, true, false, false, $callback);
  
  while(count($channel->callbacks)) {
      $channel->wait();
  }
  
  $channel->close();
  $connection->close();